package com.hp.ssmp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hp.ssmp.dao.CommentMapper;
import com.hp.ssmp.dao.ReplyMapper;
import com.hp.ssmp.entity.TComment;
import com.hp.ssmp.entity.TCommentReply;
import com.hp.ssmp.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service("replyService")
@Transactional
public class ReplyServiceImpl extends ServiceImpl<ReplyMapper, TCommentReply> implements ReplyService {

    @Autowired
    private ReplyMapper replyMapper;

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public boolean addReply(TCommentReply reply) {
        try {
            reply.setReplytime(new Date());
            TComment tComment = commentMapper.selectById(reply.getCommentid());
            tComment.setStatus(2L);
            commentMapper.updateById(tComment);
            return replyMapper.insert(reply) > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
